﻿//4. Write a program to convert hexadecimal numbers to their decimal representation.


using System;
using System.Collections.Generic;

class HexadecimalToDecimal
{
    static void Main()
    {
        string hexaDNumber = Console.ReadLine();
        Console.WriteLine(GetHexadecimalDecimalInt(hexaDNumber));
        Console.WriteLine(Convert.ToInt32(hexaDNumber, 16));
    }

    static int GetHexadecimalDecimalInt(string hexaDNumber)
    {
        int decimalNumber = 0;

        for (int i = 0; i < hexaDNumber.Length; i++)
        {
            switch (hexaDNumber[i])
            {
                case 'A':
                    decimalNumber += 10 * (int)Math.Pow(16, hexaDNumber.Length - 1 - i);
                    break;
                case 'B':
                    decimalNumber += 11 * (int)Math.Pow(16, hexaDNumber.Length - 1 - i);
                    break;
                case 'C':
                    decimalNumber += 12 * (int)Math.Pow(16, hexaDNumber.Length - 1 - i);
                    break;
                case 'D':
                    decimalNumber += 13 * (int)Math.Pow(16, hexaDNumber.Length - 1 - i);
                    break;
                case 'E':
                    decimalNumber += 14 * (int)Math.Pow(16, hexaDNumber.Length - 1 - i);
                    break;
                case 'F':
                    decimalNumber += 15 * (int)Math.Pow(16, hexaDNumber.Length - 1 - i);
                    break;
                default:
                    decimalNumber += (int)char.GetNumericValue(hexaDNumber[i]) * (int)Math.Pow(16, hexaDNumber.Length - 1 - i);
                    break;
            }
        }
        return decimalNumber;
    }
}
